function Sound() {
  
  this.instances = {};
  
  this.totalInstances = 0;
  
  this.loadedSounds = 0;
  
  this.loaded = false;
  
  this.percentageLoaded = 0;
  
  
  this.init = function() {
    if(Object.keys(resources.sounds).length == 0) {
      this.percentageLoaded = 100;
    } else {
      soundManager.setup({
        debugMode : DEBUG,
        url : "swf/",
        onready: function() {
          sound.loadSounds();
        },
        ontimeout: function() {
          alert("Cannot play sound!");
        }
      });
    }
    for(var name in resources.sounds) {
      this.totalInstances += resources.sounds[name].instances;
    }
  };
  
  
  this.loadSounds = function() {
    for(var name in resources.sounds) {
      for(var i = 0; i < resources.sounds[name].instances; i++) {
        soundManager.createSound({
          id : name + "_instance_" + i,
          url : resources.sounds[name].source,
          autoLoad : true,
          volume: 40,
          multiShot: false,
          onload : function() {
            sound.reportSoundLoaded();
          }
        });
      }
      this.instances[name] = { position : 0, count : resources.sounds[name].instances };
    }
  };
  
  
  this.reportSoundLoaded = function() {
    this.loadedSounds++;
    this.percentageLoaded = Math.ceil(100 * this.loadedSounds / this.totalInstances);
    if(this.loadedSounds == this.totalInstances) {
      this.loaded = true;
    }
  };
  
  
  this.finishedLoading = function() {
    return this.loaded;
  };
  
  
  this.play = function(name) {
    if(this.loaded) {
      soundManager.play(name + "_instance_" + this.instances[name].position);
      this.instances[name].position++;
      if(this.instances[name].position >= this.instances[name].count) {
        this.instances[name].position = 0;
      }
    };
  };
  
}